var app = getApp();
var $ = require("../../utils/httpHelper.js")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    objarr: [],
    currentTab: 0,
    page: 1,
    pagesize: 10,
    totalpage: 0,//最大页数
    height: 0,
    width:0,
    nomore: true,
    isOver:true,
    total_point:0,
    add:'+',
    jian:'-'
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var self = this;
    wx.getSystemInfo({
      success: function (res) {
        self.setData({ 
          height: res.windowHeight-180,
          width:res.windowWidth
         })
      }
    })
    this.getData()

  },

  getData(){
    let params = {
      rd_session: app.globalData.userInfo.rd_session,
      page: this.data.page,
      pagesize: this.data.pagesize,
      types: this.data.currentTab
    }
    $.httpPost("point_record", params, (data, err) => {
      this.setData({
        objarr: data.data.list,
        total_point: data.data.total_point,
        totalpage: data.total_page
      })
    })
  },
  clicktab(e) {
    console.log(e.target)
    let tab = e.target.dataset.tab
    if (this.data.currentTab != tab) {
      this.setData({
        currentTab: tab,
        page: 1
      })
      this.getData()
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    console.log("xila")
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  //滑动到底部 上拉加载
  scrollBottom: function () {
    this.data.page++
    if (this.data.page > this.data.totalpage) {
      this.setData({
        nomore: false
      })
    } else {
      let params = {
        rd_session: app.globalData.userInfo.rd_session,
        page: this.data.page,
        pagesize: this.data.pagesize,
        types: this.data.currentTab
      }
      $.httpPost("point_record", params, (data, err) => {
        let arr = this.data.objarr;
        for (let item of data.data.list) {
          arr.push(item);
        }
        this.setData({
          objarr: arr
        })
      })
     
      
    }

  },

  tojf(){
    wx.navigateTo({
      url: '/pages/jifen/jfgood',
    })
  },
  togz() {
    wx.navigateTo({
      url: '/pages/jifen/gz?info='+'jf'
    })
  }



})